package spe.ui.menu.popup.actionprovider;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.ide.IDE;

import spe.model.notation.SPEMDiagram;
import spe.model.spem.MethodConfiguration;
import spe.model.spem.MethodLibrary;
import spe.model.spem.MethodPlugin;
import spe.model.spem.ProcessPackage;
import spe.ui.editor.SPEMEditorInput;
import spe.ui.editor.SPEMGraphEditor;

public class MyOpenAction extends Action 
{
	private Object object;
	private IWorkbenchPage page = null;
	
	public MyOpenAction(Object obj, IWorkbenchPage p)
	{
		super();
		
		this.object = obj;
		this.page = p;
	}
	
	public void run()
	{
		//System.out.println(String.format("You've double-clicked on %s", object));
		
		if(object instanceof MethodLibrary)
		{
			return;
		}
		
		if(object instanceof MethodPlugin)
		{
			/*
			MethodPlugin mp = (MethodPlugin)object;
			MethodLibrary ml = (MethodLibrary)mp.getParent();
			//SPEMDiagram diagram = SPEMFactory.eInstance.createSPEMDiagram();
			//diagram.addElement(mp);
			IFolder folder = ml.getProject().getFolder(ml.getName());
			IFile dataFile = folder.getFile("spe-model.xml");
			//System.out.println(String.format("[MyOpenAction] Fullpath: %s; Existed: %s",dataFile.getFullPath(), dataFile.exists()));
			try {
				IDE.openEditor(page, dataFile);
			} catch (PartInitException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return;
			*/
		}
		
		if(object instanceof MethodConfiguration)
		{
			return;
		}
		
		if(object instanceof ProcessPackage)
		{
			return;
		}
	}
}
